package urnav.example.com;


import geocoding.ALGOTrip;
import geocoding.Converter;
import geocoding.CustomNodes;
import graph.ALGOGraph;
import graph.SearchableGraph;

import java.util.ArrayList;

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.MyLocationOverlay;
import org.osmdroid.views.overlay.OverlayItem;

import osm.OsmReader;
import osm.TagReader;
import routing.Items;
import routing.Landmark;
import routing.LandmarkMaker;
import routing.Landmarks;
import routing.Landmarks2;
import routing.MyPathOverlay;
import routing.Node;
import routing.Segment;
import routing.SegmentMaker;
import routing.Smooth;
import routing.Trip;
import routing.TripControl;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.TextView;

public class URNavActivity extends Activity

{
    public LocationManager myLocManager;
    public LocationListener myLocListener;
    public MyLocationOverlay myLocOverlay;
    private MapView myMap;
    private TextView myText;
	private ItemizedIconOverlay<OverlayItem> myItemizedOverlay;
	Time myTime = new Time();

	private ResourceProxy mResourceProxy;
	public ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
	TripControl myTControl = new TripControl();
	OsmReader myOsmReader= new OsmReader();
	Converter myConverter = new Converter();
	Trip myTrip = new Trip();
	Items myItems = new Items();
	private ALGOGraph myGraph;
	Projection myProjection;
	Canvas myCanvas = new Canvas();
	Smooth mySmooth = new Smooth();
	Logger myLogger = new Logger();
	

	public static Context actVar;
    boolean isFirstRun=true;
    boolean isOnPause=false;
    boolean isStartSet=false;
    boolean simpleMode=true;
    int routeID=0; 
    int currentSelected=0;
	int startNodeID=0;
	int targetNodeID=0;
	int lati;
	int longi;
	int lastLM=10; 
	long lastLMtime; 
	String lastOutput = "";
	public static boolean openActivity=false; 
	boolean finished=false; 
	CustomNodes cn; 
	TextView debug; 
	
	
	static final int QAlter = 0;
	static final int QErfahrung = 1;
	static final int QNEindeutig = 2;
	static final int QNHilfreich = 3; 
	static final int QZielgefunden = 4;
	static final int QRoute = 5;
	static final int QNavigation = 6;
	static final int QNutzung = 7;
	static final int QNObjekt = 8;
	static final int QNErkennen = 9;
	static final int QNAnderes = 10;
	static final int QVergleich1 = 11;
	static final int QVergleich2 = 12;
	static final int QVergleich3 = 13;
	static final int QAnweisung = 14;
	static final int QRouteselect = 15;
	static final int QGeschlecht = 16;
	static final int QModus = 17;
	static final int QRun = 18;
	static final int QZiel = 19;
	
	
	String TAG = "URNav";
	public ALGOTrip trip;
	
	private Handler myHandler = new Handler(){
		public void handleMessage(Message myMessage) {
		handle(myMessage);	
		}
	};
	
	private Handler myHandler2 = new Handler(){
		public void handleMessage(Message myMessage) {
		handle2(myMessage);	
		}
	};
	
	final Runnable runLandMarkMode = new Runnable(){
		public void run(){
			myTControl.checkTripLandMarkMode(myLocOverlay, cn, targetNodeID, myTrip, myHandler, 
					myText, lastLMtime, debug);
			myHandler.postDelayed(this,2000);
			Log.i(TAG, "openActivity: " + openActivity);
		}
		};
		
	final Runnable runSimpleMode = new Runnable(){
		public void run(){
			myTControl.checkTripSimpleMode(myLocOverlay, cn, targetNodeID, myTrip, myHandler, myText);
			myHandler.postDelayed(this,500);
			}
			};
			
	final Runnable runSurvey = new Runnable(){
		public void run(){
			Survey mySurvey= new Survey();
			mySurvey.waitSurvey(openActivity, myHandler2);
			myHandler2.postDelayed(this,1000);
		}
		};

	
	
public void onCreate(Bundle savedInstanceState)

{
	
super.onCreate(savedInstanceState);

this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
actVar=this;

Intent qrouteSelectIntent = new Intent(URNavActivity.this, QRouteselect.class);
URNavActivity.this.startActivityForResult(qrouteSelectIntent, QRouteselect);

initGraph();
setMap();
initMyLocation();
myItems.getItems(cn);
TagReader myTagReader2 = new TagReader();
myTagReader2.readTags(cn);
initOverlay(myItems.getItems(cn));
Landmarks2 myLm2 = new Landmarks2();
myLm2.getLandmarks(cn);

 }
 


//Reads the customized OSM- xml- file and creates the searchable graph
public void initGraph(){
	myGraph = myOsmReader.readXml();

	((SearchableGraph)myGraph).init();
	
	cn = myOsmReader.getNodes(); 
			
	
}


//Initiating the MyLocationOverlay 
private void initMyLocation() {
	
	myLocOverlay = new MyLocationOverlay(this, myMap);
	myLocOverlay.enableMyLocation();
	myLocOverlay.enableFollowLocation();
	myMap.getOverlays().add(myLocOverlay); 
	
	
    
}

//Initiating the ItemizedOverlay to show route destinations/ important facilities
public void initOverlay(ArrayList<OverlayItem> items){
        /* OnTapListener for the Markers, shows a simple Toast. */
//        this.
        myItemizedOverlay = new ItemizedIconOverlay<OverlayItem>(items,
                        new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
        						
//        						Handling the Tap- Events
                                @Override
                                public boolean onItemSingleTapUp (final int index, final OverlayItem item) {
                                      
                                        return true; 
                                }

                                @Override
                                public boolean onItemLongPress(final int index, final OverlayItem item) {

                                        		
                                        return false;
                                }
                        }, mResourceProxy);
        
        this.myMap.getOverlays().add(this.myItemizedOverlay);
        myProjection = myMap.getProjection();

        ;}
		

//Sets up the OSM- Display
public void setMap(){

	setContentView(R.layout.main);
	
	/* Settings for the Mapview */
	
	myMap = (MapView) this.findViewById(R.id.mapview);

	myMap.setTileSource(TileSourceFactory.MAPNIK);
	myMap.setBuiltInZoomControls(true);
	myMap.setMultiTouchControls(true);
	myMap.getController().setZoom(16);
	myMap.getController().setCenter(new GeoPoint(4899896,12091809));
	
	myText=(TextView)findViewById(R.id.textview);
	debug=(TextView)findViewById(R.id.debug); 

}






//Menu for test purposes, will be replaced with menu for preferences etc.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
    
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.simple:  {
        	simpleMode=true; 
        	
        	break;
        }
        case R.id.landmark:{
        	simpleMode=false;
        	break;
        }
        
        case R.id.switchr:{
        	
        	if (routeID==2) {
        		routeID=3;
        	}
        	if (routeID==3) {
        		routeID=2;
        	}
        	if (routeID==4) {
        		routeID=5;
        	}
        	if (routeID==5) {
        		routeID=4;
        	}

        	myText.setText("RouteID set to " + routeID);
        	break;
        }
        
        case R.id.route:{
        	Search mySearch=new Search();
        	

        	
        	
//        	Search for route, store it in Trip
        	
//        	PT -> Mensa
        	if (routeID==0) {
        	startNodeID=cn.getPosition("322090939");
        	targetNodeID=cn.getPosition("890101107"); 
        	
        	}
        	
//        	Mensa -> PT
        	if (routeID==1) {
        	startNodeID=cn.getPosition("890101107");
        	targetNodeID=cn.getPosition("322090939"); 
    		}
        	
//        	Haltestelle -> PT
        	if (routeID==2) {
        	startNodeID=cn.getPosition("1190880755");
        	targetNodeID=cn.getPosition("322090939"); 
			}
        	
//        	PT -> Haltestelle
        	if (routeID==3) {
        	startNodeID=cn.getPosition("322090939");
        	targetNodeID=cn.getPosition("1190880755"); 
			}
        	
//        	PT -> Physik
        	if (routeID==4) {
        	startNodeID=cn.getPosition("322090939");
        	targetNodeID=cn.getPosition("311871492"); 
        	}
        	
//        	Physik -> PT
        	if (routeID==5) {
        	startNodeID=cn.getPosition("311871492");
        	targetNodeID=cn.getPosition("322090939");
        	}
        	
        	myLogger.appendLog("route started, ID: " + routeID);
        	myLogger.appendLog("route started, simpleMode=: " + simpleMode);
        	myLogger.appendLog("route started, Time=: " + myTime.getTime());
        	
//        	startNodeID=myOsmReader.getNodes().getPosition("1101816534");
//        	targetNodeID=myOsmReader.getNodes().getPosition("33772083");
        	
        	myTrip=mySearch.search(startNodeID, targetNodeID, myGraph, cn, myTrip, myLocOverlay);
        	
//        	if (simpleMode) {
//        		mySmooth.smoothTripSimple(myTrip, cn);
//        	}
//        	
//        	else {
//        		mySmooth.smoothTripLandmark(myTrip, cn);
//        	}
//        	NewTrip myNewTrip = new NewTrip();
//        	myTrip = myNewTrip.makeNewTrip(myTrip, cn);
        	
        	for (int i=0; i<myTrip.getTripList().size(); i++){
        		Log.i(TAG, "IN TRIP: " + String.valueOf(myTrip.getTripItem(i)));
        	}
        	
        	showSolution();

        	Landmarks myLandmarks = new Landmarks();
        	myLandmarks.setLandmarks(cn, myTrip);
        
        	SegmentMaker sm = new SegmentMaker();
        	ArrayList<Segment> segments = sm.makeSegments(cn, myTrip);  
        	

			
        	myTrip.setSegments(segments); 
        	
        	LandmarkMaker lmm = new LandmarkMaker();
        	ArrayList<Integer> landmarks =  lmm.makeLandmarks(cn); 
        	myTrip.setLandmarks(landmarks); 
        	
        	myTrip = lmm.getPossibleLandmarksForSegment(cn, myTrip);
        	
        	 
        	
        	myTrip = lmm.assignNodes2Landmarks(myTrip, cn); 
        	myTrip = lmm.assignLandmarks2Nodes(myTrip, cn);
        	
        	segments = myTrip.getSegments();
        	
        	myTrip = lmm.removeDuplicateLandmarksPerNode(myTrip, cn); 
        	myTrip = lmm.createLandmarkDirectionText(myTrip, cn);
        	
        	
        	
        	if (myTrip.getTripList().size()>0){
        		startTrip();
        	}
        	
        	
        	
        	break;
        }	
        
//        Reset Items- Overlay
        case R.id.reset:{
    		items.clear();
    		
    		myMap.getOverlays().clear();
    		myMap.invalidate();
    		
    		myHandler.removeCallbacks(runLandMarkMode);
    		myHandler.removeCallbacks(runSimpleMode);
    		initMyLocation();
    		initOverlay(myItems.getItems(cn));
    		TripControl myTControl = new TripControl();
    		
        	break;
        }
        
        case R.id.stop:  {
        	finish();
        }
    }
        return true;
	}




protected void onPause(){

	super.onPause();
	
}

protected void onDestroy(){

	super.onDestroy();
	
}

protected void onResume(){

super.onResume();

}

//Show nodes on the Trip to destination
public void showSolution(){

		items.clear();
	
		myMap.getOverlays().clear();
		items= myItems.getItems(myTrip, myGraph, cn);
		initMyLocation();
		myMap.invalidate();
		initOverlay(items);
	
}

//Check where user is on the route
public void startTrip(){
	
		myTControl.prepare(myTrip, cn, myLocOverlay); 
		
		if (simpleMode==false) {
			myHandler.postDelayed(runLandMarkMode,2000);
		}
		else {
			myHandler.postDelayed(runSimpleMode,2000);
		}
}

//Refresh Route- Overlay according to users position
public void handle (Message myMessage){
	Bundle myBundle= myMessage.getData();
	
	
	boolean finish=myBundle.getBoolean("finish");
	if (finish==true) {
		Log.i(TAG, "Finish in Main");
		myHandler.removeCallbacks(runLandMarkMode);
		myHandler.removeCallbacks(runSimpleMode);
		myHandler2.postDelayed(runSurvey,5000);
		
	}
	

	
//	Redrawing items & Path
	int currentNodePosition=myBundle.getInt("currentNodePosition");
	
	items.clear();
	myMap.getOverlays().remove(myItemizedOverlay);
	items= myItems.getItems(currentNodePosition, myTrip, myGraph, cn);
	MyPathOverlay myPath = new MyPathOverlay(-16776961, actVar);
	myPath.clearPath();
	
	for (int i=currentNodePosition; i<myTrip.getTripList().size(); i++) {
		myPath.addPoint(myConverter.convertDouble(cn.getDlati(myTrip.getTripItem(i))), myConverter.convertDouble(myOsmReader.getNodes().getDlongi(myTrip.getTripItem(i))));
	}
	
//	initMyLocation();
	myMap.invalidate();
	initOverlay(items);
	myPath.draw(myCanvas, myMap, false);
	myMap.getOverlays().add(myPath);
	
//	Checking if LM has changed
	
	int currentLM=myBundle.getInt("currentLM");
	if (lastLM != currentLM) {
		lastLM=currentLM; 
		lastLMtime=0; 

	}
	
//	Check if there is a new landmark description
	
	String output=myBundle.getString("output");
	boolean newLandmarkShown = myBundle.getBoolean("landmarkshown");
//	myText.setText("Main: " + output);
	if (newLandmarkShown && !openActivity) {
		myLogger.appendLog("new landmark description: " + output);
		myLogger.appendLog("at: " + myLocOverlay.getLastFix());
		myLogger.appendLog("at Time: " + myTime.getTime());


    	Intent qanweisungIntent = new Intent(URNavActivity.this, QAnweisung.class);
    	qanweisungIntent.putExtra("output", output);
    	URNavActivity.this.startActivityForResult(qanweisungIntent, QAnweisung);
    	openActivity=true; 
	    
	}
	lastOutput=output;

	
	
}

public void handle2 (Message myMessage){
	Bundle myBundle= myMessage.getData();
	
	
	boolean open=myBundle.getBoolean("open");
	if (open==false) {
//		myHandler2.removeCallbacks(runSurvey);
		Log.i(TAG, "Finished: " + String.valueOf(finished));
		if (finished==false) {
    	Intent qzielIntent = new Intent(URNavActivity.this, QZiel.class);
    	URNavActivity.this.startActivityForResult(qzielIntent, QZiel);
    	finished=true; 
		}
	}
}





protected void onActivityResult(int requestCode, int resultCode,
        Intent resultIntent) {
	  Log.i(TAG, "RESULT");
    if (requestCode == QAlter) {
        if (resultCode == RESULT_OK ) {
        	
        	String alter = resultIntent.getStringExtra("Alter");
//        	Log.i(TAG, "From form, Main: " +  alter);
        	myLogger.appendLog("Answered Q1:Alter: " + alter);
        	myLogger.appendLog(myTime.getTime());
        	
        	Intent qerfahrungIntent = new Intent(URNavActivity.this, QErfahrung.class);
        	URNavActivity.this.startActivityForResult(qerfahrungIntent, QErfahrung);
        	
        }
    }
    
    if (requestCode == QErfahrung) {
        if (resultCode == RESULT_OK ) {
        	
        	String erfahrung = resultIntent.getStringExtra("Erfahrung");
        	Log.i(TAG, "From form, Main (Erfahrung): " +  erfahrung);
        	myLogger.appendLog("Answered Q2:Erfahrung: " + erfahrung);
        	myLogger.appendLog(myTime.getTime());
        	
        	Intent qgeschlechtIntent = new Intent(URNavActivity.this, QGeschlecht.class);
        	URNavActivity.this.startActivityForResult(qgeschlechtIntent, QGeschlecht);
        	
        	
        }
    }
    
    if (requestCode == QGeschlecht) {
        if (resultCode == RESULT_OK ) {
        	
        	String geschlecht = resultIntent.getStringExtra("Geschlecht");
        	Log.i(TAG, "From form, Main (Geschlecht): " +  geschlecht);
        	myLogger.appendLog("Answered Q3:Geschlecht: " + geschlecht);
        	myLogger.appendLog(myTime.getTime());
        	
        	

        }
    }
    
    if (requestCode == QNEindeutig) {
        if (resultCode == RESULT_OK ) {
        	
        	String eindeutig = resultIntent.getStringExtra("Eindeutig");
        	Log.i(TAG, "From form, Main (Eindeutig): " +  eindeutig);
        	myLogger.appendLog("Answered QN:Eindeutig: " + eindeutig);
        	myLogger.appendLog(myTime.getTime());
        	
        	Intent qhilfreichIntent = new Intent(URNavActivity.this, QNHilfreich.class);
        	URNavActivity.this.startActivityForResult(qhilfreichIntent, QNHilfreich);
        	openActivity=true;

        }
    }
    
    if (requestCode == QNHilfreich) {
        if (resultCode == RESULT_OK ) {
        	
        	String hilfreich = resultIntent.getStringExtra("Hilfreich");
        	Log.i(TAG, "From form, Main (Hilfreich): " +  hilfreich);
        	myLogger.appendLog("Answered QN:Hilfreich: " + hilfreich);
        	myLogger.appendLog(myTime.getTime());
        	
        	if (simpleMode==false) {
        		Intent qnobjektIntent = new Intent(URNavActivity.this, QNObjekt.class);
            	URNavActivity.this.startActivityForResult(qnobjektIntent, QNObjekt);
            	openActivity=true;
        	}
        	

        }
    }
    
    if (requestCode == QZielgefunden) {
        if (resultCode == RESULT_OK ) {
        	
        	String zielGefunden = resultIntent.getStringExtra("Zielgefunden");
        	Log.i(TAG, "From form, Main (Zielgefunden): " +  zielGefunden);
        	myLogger.appendLog("Answered QN:Zielgefunden: " + zielGefunden);
        	myLogger.appendLog(myTime.getTime());
        	openActivity=false;

        	

        }
    }
    
    if (requestCode == QAnweisung) {
        if (resultCode == RESULT_OK ) {
        	
        	
        	openActivity = false; 
//        	Intent qeindeutigIntent = new Intent(URNavActivity.this, QNEindeutig.class);
//        	URNavActivity.this.startActivityForResult(qeindeutigIntent, QNEindeutig);
//        	openActivity=true;
        }
    }
    
    if (requestCode == QNObjekt) {
        if (resultCode == RESULT_OK ) {
        	
        	String objekt = resultIntent.getStringExtra("Objekt");
        	Log.i(TAG, "From form, Main (Objekt): " +  objekt);
        	myLogger.appendLog("Answered QN: Objekt: " + objekt);
        	myLogger.appendLog(myTime.getTime());
        	
        	if (!(objekt.equals("Nein"))) {
        	Intent qnerkennenIntent = new Intent(URNavActivity.this, QNErkennen.class);
        	URNavActivity.this.startActivityForResult(qnerkennenIntent, QNErkennen);
        	openActivity=true;
        	}
        	
        	else {
        		openActivity=false;
        	}
        }
    }
    
    if (requestCode == QNErkennen) {
        if (resultCode == RESULT_OK ) {
        	
        	String erkennen = resultIntent.getStringExtra("Erkennen");
        	Log.i(TAG, "From form, Main (Erkennen): " +  erkennen);
        	myLogger.appendLog("Answered QN: Erkennen: " + erkennen);
        	myLogger.appendLog(myTime.getTime());
        	
        	Intent qnanderesIntent = new Intent(URNavActivity.this, QNAnderes.class);
        	URNavActivity.this.startActivityForResult(qnanderesIntent, QNAnderes);
        	openActivity=true;

        }
    }
    
    if (requestCode == QNAnderes) {
        if (resultCode == RESULT_OK ) {
        	
        	String anderes = resultIntent.getStringExtra("Anderesn");
        	Log.i(TAG, "From form, Main (Anderes): " +  anderes);
        	myLogger.appendLog("Answered QN: Anderes Objekt: " + anderes);
        	myLogger.appendLog(myTime.getTime());
        	openActivity=false;

        	

        }
    }
    
    if (requestCode == QRouteselect) {
        if (resultCode == RESULT_OK ) {
        	
        	String select = resultIntent.getStringExtra("Select");
        	Log.i(TAG, "From form, Main (Select): " +  select);
        	myLogger.appendLog("Answered QN: Route ausgewählt: " + select);
        	myLogger.appendLog(myTime.getTime());
        	
        	routeID= Integer.valueOf(select);
        	Log.i(TAG, "Route selected: " + routeID);
        	
        	Intent qmodusSelectIntent = new Intent(URNavActivity.this, QModus.class);
        	URNavActivity.this.startActivityForResult(qmodusSelectIntent, QModus);
        	
        	

        }
        
        if (resultCode == RESULT_CANCELED ) {
        	
        }
    }
    
    if (requestCode == QModus) {
        if (resultCode == RESULT_OK ) {
        	
        	String modus = resultIntent.getStringExtra("Modus");
        	Log.i(TAG, "From form, Main (Modus): " +  modus);
        	myLogger.appendLog("Answered QN: Modus ausgewählt: " + modus);
        	myLogger.appendLog(myTime.getTime());
        	
        	if (modus.equals("Standard- Modus")) {
        		simpleMode=true;
        	}
        	
        	if (modus.equals("Landmarken- Modus")) {
        		simpleMode=false;
        	}
        	Log.i(TAG, "Modus selected: " + simpleMode);
        	
        	Intent qrunIntent = new Intent(URNavActivity.this, QRun.class);
        	URNavActivity.this.startActivityForResult(qrunIntent, QRun);
        	
        }
    }
    
    if (requestCode == QRun) {
        if (resultCode == RESULT_OK ) {
        	
        	String run = resultIntent.getStringExtra("Run");
        	Log.i(TAG, "From form, Main (Run): " +  run);
        	myLogger.appendLog("Answered QN: Run: " + run);
        	myLogger.appendLog(myTime.getTime());
        	
        	if (run.equals("1.")) {
            	Intent qalterIntent = new Intent(URNavActivity.this, QAlter.class);
            	URNavActivity.this.startActivityForResult(qalterIntent, QAlter);
        	}    	
        	
        }
    }
    
    if (requestCode == QZiel) {
        if (resultCode == RESULT_OK ) {
        	
//        	String vergleich1 = resultIntent.getStringExtra("Ziel");
        	Log.i(TAG, "From form, Main (Ziel)");
        	myLogger.appendLog("Ziel ");
        	myLogger.appendLog(myTime.getTime());
   	
    		Intent qvergleich1Intent = new Intent(URNavActivity.this, QVergleich1.class);
        	URNavActivity.this.startActivityForResult(qvergleich1Intent, QVergleich1);
        	
        }
    }
    
    if (requestCode == QVergleich1) {
        if (resultCode == RESULT_OK ) {
        	
        	String vergleich1 = resultIntent.getStringExtra("Vergleich1");
        	Log.i(TAG, "From form, Main (Vergleich1): " +  vergleich1);
        	myLogger.appendLog("Answered QN: Vergleich1: " + vergleich1);
        	myLogger.appendLog(myTime.getTime());
   	
    		Intent qvergleich2Intent = new Intent(URNavActivity.this, QVergleich2.class);
        	URNavActivity.this.startActivityForResult(qvergleich2Intent, QVergleich2);
        	
        }
    }
    
    if (requestCode == QVergleich2) {
        if (resultCode == RESULT_OK ) {
        	
        	String vergleich2 = resultIntent.getStringExtra("Vergleich2");
        	Log.i(TAG, "From form, Main (Vergleich2): " +  vergleich2);
        	myLogger.appendLog("Answered QN: Vergleich2: " + vergleich2);
        	myLogger.appendLog(myTime.getTime());
        	
    		Intent qvergleich3Intent = new Intent(URNavActivity.this, QVergleich3.class);
        	URNavActivity.this.startActivityForResult(qvergleich3Intent, QVergleich3);
        	
        	
        }
    }
    
    if (requestCode == QVergleich3) {
        if (resultCode == RESULT_OK ) {
        	
        	String vergleich3 = resultIntent.getStringExtra("Vergleich3");
        	Log.i(TAG, "From form, Main (Vergleich3): " +  vergleich3);
        	myLogger.appendLog("Answered QN: Vergleich3: " + vergleich3);
        	myLogger.appendLog(myTime.getTime());
        	
   	
        	
        }
    }
}





}